$(function(){
	checktinfo();
})
function checktinfo(){
	$.ajax({
        url: "/blackhouse/teacherinfo",
        type: "post",
        data: { "code":0},
        dataType: "json",
        success: function(e) {
        	var html=""
        	for(var i = 0;i<e.length;i++){
        		html+="<tr>";
        		html+="<td>"+e[i].tCode+"</td>";
        		html+="<td>"+e[i].tName+"</td>";
        		html+="<td>"+e[i].tSex+"</td>";
        		html+="<td>"+e[i].tAge+"</td>";
        		html+="<td>"+e[i].tEducation+"</td>";
        		html+="<td>"+e[i].tGoodAt+"</td>";   
        		html+="<td>"+e[i].tQQ+"</td>";
        		html+="<td>"+e[i].tPhone+"</td>";
        		html+="<td>"+e[i].tEamil+"</td>";
        		html+="<td>"+e[i].tAddress+"</td>"; 		
        		html+="<td><button class='btn btn-primary btn-lg' data-toggle='modal' data-target='#myModal' style='font-size: 12px; width: 20px;text-indent: -12px; height: 10px; line-height: 3px!important;' onclick='teacherinfo(this)'  tag='"+e[i].tCode+"'>" +
        				"修改</button>&nbsp;&nbsp;<button class='btn btn-primary btn-lg' style='font-size: 12px; width: 20px;text-indent: -12px; height: 10px; line-height: 3px!important;'  tag='"+e[i].tCode+"' onclick='deltinfo(this)'>删除</button></td>";
        		html+="</tr>";
        	}
        	$("#teacher-tbody").html(html);
        }
    })
}
function deltinfo(e){
	var r=confirm("确认删除该老师信息吗");
	if (r==true)
	{
		var key=$(e).attr("tag");
		$.ajax({
	        url: "/blackhouse/teacherinfo",
	        type: "post",
	        data: { "code": 1,"key":key },
	        dataType: "json",
	        success: function(e) {
	        		if(e){
	        			swal("删除成功", "该老师已被删除", "success");
	        			checktinfo();
	        		}else{
	        			swal("删除失败", "后台异常", "error");
	        		}
	        	}
	        })
	}
	else
	{
		swal("取消成功", "请求取消", "error");
	}
	
}
function seektinfo(e){
	$.ajax({
        url: "/blackhouse/teacherinfo",
        type: "post",
        data: { "code":2,"ID":$("#name").val()},
        dataType: "json",
        success: function(e) {
        	var html=""
        	for(var i = 0;i<e.length;i++){
        		html+="<tr>";
        		html+="<td>"+e[i].tCode+"</td>";
        		html+="<td>"+e[i].tName+"</td>";
        		html+="<td>"+e[i].tSex+"</td>";
        		html+="<td>"+e[i].tAge+"</td>";
        		html+="<td>"+e[i].tEducation+"</td>";
        		html+="<td>"+e[i].tGoodAt+"</td>";   
        		html+="<td>"+e[i].tQQ+"</td>";
        		html+="<td>"+e[i].tPhone+"</td>";
        		html+="<td>"+e[i].tEamil+"</td>";
        		html+="<td>"+e[i].tAddress+"</td>"; 		
        		html+="<td><button class='btn btn-primary btn-lg' data-toggle='modal' data-target='#myModal' style='font-size: 12px; width: 20px;text-indent: -12px; height: 10px; line-height: 3px!important;' onclick='teacherinfo(this)'  tag='"+e[i].tCode+"'>" +
        				"修改</button>&nbsp;&nbsp;<button class='btn btn-primary btn-lg' style='font-size: 12px; width: 20px;text-indent: -12px; height: 10px; line-height: 3px!important;'  tag='"+e[i].tCode+"' onclick='deltinfo(this)'>删除</button></td>";
        		html+="</tr>";
        	}
        	$("#teacher-tbody").html(html);
        }
    })
}
function teacherinfo(e){
	var key=$(e).attr("tag");
	$.ajax({
		url:"/blackhouse/teacherinfo",
		data:{"code":3,"key":key},
		type:"post",
		dataType:"json",
		 success: function(e) {
			 $("#tCode").val(e[0].tCode);
				$("#tname").val(e[0].tName);
				if(e[0].tSex=="男"){
					 $("#sex1").prop("checked", true);
			         $("#sex2").prop("checked", false);
			     } else {
			         $("#sex2").prop("checked", true);
			         $("#sex1").prop("checked", false);
			     };
				$("#tage").val(e[0].tAge);
				$("#tgoodat").val(e[0].tGoodAt);
				$("#tphone").val(e[0].tPhone);
				$("#tQQ").val(e[0].tQQ);
				$("#temail").val(e[0].tEamil);
				$("#taddress").val(e[0].tAddress)
		 }
	})
}
function changetinfo(){
		$.ajax({
			url:"/blackhouse/teacherinfo",
			data:{"tage":$("#tage").val(),"tgoodat":$("#tgoodat").val(),"tPhone":$("#tphone").val(),"tQQ":$("#tQQ").val(),"temail":$("#temail").val(),"taddress":$("#taddress").val(),"tCode":$("#tCode").val(),"code":"4"},
			type:"post",
			dataType:"json",
			 success: function(e) {
				 if(e){
					 alert('修改成功');
					 checktinfo();
				 }else{
					 alert('修改失败');
				 }
			 }
		})
	
}